﻿using AutoMapper;
using MediatR;
using T_settlement.API.Application.Command.settlementCommand;
using T_settlement.Domain;
using T_settlement.Infrastructure.Interfacec;

namespace T_settlement.API.Application.CommandHandlers.settlementCommandHandlers
{
    public class AddsettlementHandlers  :IRequestHandler<AddsettlementCommand, int>
    {
        private readonly IMapper mapper;
         private readonly lsettlementRepository lsettlementRepository;

        public AddsettlementHandlers(lsettlementRepository lsettlementRepository, IMapper mapper)
        {
            this.lsettlementRepository = lsettlementRepository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(AddsettlementCommand request, CancellationToken cancellationToken)
        {

            var Info = mapper.Map<Settlement>(request);
            Info.Number = "SY" + DateTime.Now.ToString("yyyyMMddss");
            Info.CreateDate = DateTime.Now;
            Info.CheckState = request.CheckState=2;    



            //var info = new Settlement();
            //info.Number = "SY" + DateTime.Now.ToString("yyyyMMddss");
            //info.Nnit = request.Nnit;
            //info.PayType = request.PayType;
            //info.Tonnage = request.Tonnage;
            //info.NnitPrice = request.NnitPrice;
            //info.Amount = request.Amount;
            //info.Attn = request.Attn;
            //info.BusinessTime = request.BusinessTime;
            //info.Remark = request.Remark;
            //return await lsettlementRepository.AddAsync(info);
            return await lsettlementRepository.AddAsync(Info);
        }
    }
}
